<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="sun.applet.resources.MsgAppletViewer_it"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ELENCO STANZE</title>
<style type="text/css">
<!--
.style1 {font-family: Verdana, Calibri, Cambria}
.style3 {font-family: Verdana, Calibri, Cambria; font-size: small; }
.style4 {
	font-family: Verdana, Calibri, Cambria;
	font-weight: bold;
	font-style: italic;
	color: #FFFFFF;
}
body,td,th {
	font-family: Verdana, Calibri, Cambria;
	font-size: small;
}
body {
	background-color: #CCCCCC;
}
-->
</style>
</head>

<body>
<table width="700" height="422" border="0" align="center">
  <tr>
    <td align="center" valign="middle"><img src="images/title.png" width="700" height="100"></td>
  </tr>
  <tr>
    <td height="257" align="center" valign="top"><table width="100%" border="0">
      <tr>
        <td align="center"><div align="left">
          <p class="style3">
          
          <%  
		
			if (session.getAttribute("user")==null)
			response.sendRedirect("loginerr.jsp");
			
			else
			{
	
			String user = session.getAttribute("user").toString();
			String type = session.getAttribute("type").toString();
			String matr = session.getAttribute("matricola").toString();
			String nome = session.getAttribute("nome").toString();
			String cogn = session.getAttribute("cognome").toString();
			
			out.println("Benvenuto " + user);
			}
		%>
		  </p>
        </div></td>
        </tr>
      <tr>
        <td class="style1"><p align="center"><strong>Elenco completo delle stanze   </strong></p></td>
        </tr>
      <tr>
        <td class="style1"><div align="center"></div></td>
        </tr>
      <tr>
        <td class="style1"><div align="center">
          <table width="100%" cellpadding="2" cellspacing="0" bordercolor="#000000" style="border:1px solid;">
            <tr>
              <td width="8%" bordercolor="#333333" bgcolor="#33CCCC" class="style3" style="border:1px solid;"><div align="center" >PROG.</div></td>
              <td width="17%" bordercolor="#333333" bgcolor="#33CCCC" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_stanze.jsp?order=1">CODICE</a></div></td>
              <td width="21%" bordercolor="#333333" bgcolor="#33CCCC" class="style3" style="border:1px solid;"><div align="center" ><a href="elenco_stanze.jsp?order=2">DENOMINAZIONE</a></div></td>
              <td width="26%" bordercolor="#333333" bgcolor="#33CCCC" class="style3" style="border:1px solid;"><div align="center" >POSIZIONE</div></td>
              <td width="28%" bordercolor="#333333" bgcolor="#33CCCC" class="style3" style="border:1px solid;"><div align="center" >NOTE</div></td>
              <td width="28%" bordercolor="#333333" bgcolor="#33CCCC" class="style3" style="border:1px solid;"><div align="center" >BENI IN STANZA</div></td>
            </tr>
			
			<%@page import = "java.sql.Connection"%>
<%@page import = "java.sql.DriverManager"%>
<%@page import = "java.sql.ResultSet"%>
<%@page import = "java.sql.Statement"%>
<%@page import = "java.sql.SQLException"%>

<%! String oracleUser = "azienda";
	String oraclePwd  = "azienda";
	Connection conn;
	String driver;
	String oracle;
	String user;
	String codice,denominazione,posizione,note; 
	Statement st;
%>
<%
	user = session.getAttribute("user").toString().toLowerCase();
	driver = "oracle.jdbc.driver.OracleDriver";
	oracle = "jdbc:oracle:thin:@localhost:1521:xe"; 
	
	try {
		Class.forName(driver);
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
	
	try {
		conn = DriverManager.getConnection(oracle, oracleUser, oraclePwd);
		st = conn.createStatement();
	} catch (SQLException e) {
		e.printStackTrace();
	}
%>

<%
				
				
				
				int order = Integer.parseInt(request.getParameter("order"));
				String qry="";
				
				switch(order)
				{
				case 1: qry = "select * from stanza order by codice";     		break; //ordine per codice
				case 2: qry = "select * from stanza order by denominazione"; 	break;//ordine per denominazione
				}
				
				ResultSet rs = st.executeQuery(qry);
				int i=0;
				
				if(rs.isBeforeFirst()&&rs.isAfterLast())
				{
					//Avvisare che non ci sono record!!!!
				}
				else
				{
					String buttonHtml="<input type=\"submit\" value=\"beni\" onclick=\"location.href='elenco_beni_instanza.jsp?order=1&codice=";
					while (rs.next())
					{
						codice = rs.getString("codice");
						denominazione = rs.getString("denominazione");
						posizione=rs.getString("posizione");
						note=rs.getString("note");
						
						String color;
	              		String bordercell;
	              		
	              		i++;
	              		
	              		if (i%2==0)
	              		{
	              			color ="\"#E0E0E0\"";
	              			bordercell="style=\"border:1px solid;\";";
	              		}
	              		else
	              		{
	              			color = "\"#EFFFEF\"";
	              			bordercell="style=\"border:1px solid;\";";
	              		}
	              		
	              		out.println("<tr>");
	              		
	              		out.println("<td align=\"right\""+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + i + "</td>"); //prog.
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + codice + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + denominazione + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + posizione + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + note + "</td>");
	              		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + buttonHtml + codice + "'\"/></td>");
	              		out.println("</tr>");
					}	
				}
				
				rs.close();
				st.close();
				conn.close();
				
             %>
          </table>
        </div></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td align="center" valign="middle">
	<form action="gestione_stanze.jsp" method="post">
		<input type="submit" name="btnreturn" value="INDIETRO" />
	</form>
	</td>
  </tr>
  <tr>
    <td align="center" valign="middle" bgcolor="#000099"><div align="right" class="style4">ELENCO STANZE  </div></td>
  </tr>
</table>
</body>
</html>
